/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_RTMP_MUXER_H
#define MK_RTMP_MUXER_H
#include "MkRtmpUtil.h"
#include "MkAmf/MkAmf.h"
#include "MkUtil/MkBuffer.h"

class MkApi CMkRtmpMuxer
{
public:
    CMkRtmpMuxer();
    ~CMkRtmpMuxer();

    static Uint32 PacketCommandMessage(const Uint32& ChunkSize, const MkString& CmdName, Uint32 TransactionId, const MkVector<MkAmfObject>& VecObj, Uint8* pBuf, Uint32 nLen, CMkBufferList& BufferList);
    static Uint32 PacketResponseMessage(const Uint32& ChunkSize, const MkString& StringResult, Uint32 TransactionId, const MkVector<MkAmfObject>& VecObj, Uint8* pBuf, Uint32 nLen, CMkBufferList& BufferList);

    static Uint32 PacketSetChunkSize(const Uint32& SetChunkSize, const Uint32& CurChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketAbortMessage(Uint32 StreamId, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketAcknowledgement(Uint32 nSize, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketWindownAcknowledgementSize(Uint32 ServerBw, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketPeerBandwidth(Uint32 WinSize, Uint8 LimitType, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    //control event message
    static Uint32 PacketStreamBegin(Uint32 StreamId, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketStreamEof(Uint32 StreamId, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketStreamDry(Uint32 StreamId, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketSetBufferLength(Uint32 StreamId, Uint32 LenPerMilliseconds, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketStreamIsRecorded(Uint32 StreamId, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketPingRequest(Uint32 TimeStamp, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketPongResponse(Uint32 TimeStamp, const Uint32& ChunkSize, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketRtmpPacket(const Uint32& ChunkSize, const MkRtmpHeaderFmtType& FmtType, const MkRtmpCommandType& MsgType, Uint16 ChunkId, Uint32 TimeStamp, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, const CMkBufferList& BufferList, CMkBufferList& OutBufferList);
protected:
private:
    static Uint32 PacketUserControlPacket(const Uint32& ChunkSize, const MkRtmpControlEvent& EventType, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketRtmpControlPacket(const Uint32& ChunkSize, const MkRtmpCommandType& MsgType, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketRtmpSystemMsgPacket(const Uint32& ChunkSize, const MkRtmpCommandType& MsgType, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketResponseMsgPacket(const Uint32& ChunkSize, const MkRtmpCommandType& MsgType, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
    static Uint32 PacketMediaPacket(const Uint32& ChunkSize, const MkRtmpCommandType& MsgType, Uint8* pBuf, Uint32 nLen, Uint32& nUsed, CMkBufferList& BufferList);
};

#endif